import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/widgets/common_btn.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/common_input.dart';
import 'package:geomancy/widgets/common_text.dart';
import 'package:geomancy/widgets/common_title.dart';
import 'package:geomancy/widgets/gallery_util/index.dart';
import 'package:photo_manager/photo_manager.dart';

class SettingFeedbackPage extends StatefulWidget {
  const SettingFeedbackPage({super.key});

  @override
  State<SettingFeedbackPage> createState() => _SettingFeedbackPageState();
}

class _SettingFeedbackPageState extends State<SettingFeedbackPage> {
  String feedbackStr = '';

  void getValueHandle(String value) {
    setState(() {
      feedbackStr = value;
    });
  }

  void openGalleryHandle() {
    GalleryUtils.openGallery(context,
      maxCount: 4,
      type: RequestType.image
    );
  }

  ///提交
  Future confirmHandle() async {

  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonHeader.appBar(context: context),
      backgroundColor: ColorStyle.pageDefaultColor,
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: ListView(
          physics: const ClampingScrollPhysics(),
          padding: EdgeInsets.fromLTRB(Constant.PAGEPADDING.w, 20.w, Constant.PAGEPADDING.w, 40.w),
          children: [
            const CommonTitleWidget(txt: '意见反馈'),
            Container(
              height: 420.w,
              margin: EdgeInsets.symmetric(vertical: 20.w),
              padding: EdgeInsets.all(10.w),
              decoration: BoxDecoration(
                  color: ColorStyle.themeLightColor,
                  border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                  borderRadius: BorderRadius.all(Radius.circular(60.w))
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(child: CommonInputWidget(
                    size: const Size(double.infinity, double.infinity),
                    hintText: '请输入问题描述：',
                    maxLines: 12,
                    maxLength: 300,
                    showBorder: false,
                    getValue: getValueHandle,
                  )),
                  Container(
                    padding: EdgeInsets.all(10.w),
                    alignment: Alignment.centerRight,
                    child: CommonText(txt: '${feedbackStr.length}/300'),
                  )
                ],
              ),
            ),
            Row(
              children: [
                GestureDetector(
                  onTap: openGalleryHandle,
                  child: Container(
                    width: 200.w,
                    height: 200.w,
                    decoration: BoxDecoration(
                        color: ColorStyle.themeLightColor,
                        borderRadius: BorderRadius.all(Radius.circular(40.w))
                    ),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image.asset('assets/icons/icon_camera_black.png', width: 64.w),
                        SizedBox(height: 4.w),
                        const CommonText(txt: '0/4'),
                      ],
                    ),
                  ),
                )
              ],
            ),
            SizedBox(height: 90.w),
            const CommonText(txt: '联系方式', weight: FontWeight.bold),
            Container(
              margin: EdgeInsets.only(bottom: 120.w),
              decoration: BoxDecoration(
                border: Border(
                    bottom: BorderSide(width: 2.w, color: ColorStyle.borderColor)
                ),
              ),
              child: CommonInputWidget(
                hintText: '请输入手机号便于联系（非必填）',
                showBorder: false,
                padding: EdgeInsets.zero,
                maxLength: 11,
                backgroundColor: Colors.transparent,
                keyboardType: TextInputType.phone,
                getValue: getValueHandle,
              ),
            ),
            Center(child: CommonBtnWidget(txt: '提交', size: Size(590.w, 80.w), onTap: confirmHandle))
          ],
        ),
      ),
    );
  }
}
